Ext.onReady(function(){
		
		
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
	Ext.Ajax.request({  
		url : 'quelle.php?ladeQuelleKategorie&id='+document.getElementById('art_id').value,  
		success: function(objServerResponse){  
			myData =  Ext.decode(objServerResponse.responseText);
			store.removeAll();
			store.loadData(myData);
	},  
		failure : function(objServerResponse){   
			alert ("Ajax Fehler!");
		}  
	});  


    // create the data store
    var store = new Ext.data.SimpleStore({
        fields: [
           {name: 'id', type: 'string'},
           {name: 'beschreibung', type: 'string'},
           {name: 'anzahl', type: 'string'},
           {name: 'gewichtung', type: 'string'},
           {name: 'aktion', type: 'string'}
        ]
    });

     var film = Ext.data.Record.create([
           {name: 'id', type: 'float'},
           {name: 'beschreibung', type: 'string'},
           {name: 'anzahl', type: 'string'},
           {name: 'gewichtung', type: 'string'},
           {name: 'aktion', type: 'string'} 
      ]);


    // create the Grid
    var grid = new Ext.grid.GridPanel({
     
        store: store,
        columns: [
            {id:'id',header: "<center><b>id</b>", width: 40, sortable: true, dataIndex: 'id', css : "text-align : center;font-size:12px;align:center;"},
            {header: "<center><b>Beschreibung</b>", width: 460, sortable: true,  dataIndex: 'beschreibung', css : "text-align : center;font-size:12px;"},
            {header: "<center><b>Anzahl Kriterien</b>", width: 100, sortable: true,  dataIndex: 'anzahl', css : "text-align : center;font-size:12px;"},
            {header: "<center><b>Gewichtung</b>", width: 150, sortable: false,  dataIndex: 'gewichtung', css : "text-align : center;font-size:12px;"},
            {header: "<center><b>Aktion</b>", width: 80, sortable: false, dataIndex: 'aktion', css : "text-align : center;font-size:12px;"}
        ],
        stripeRows: true,
       // bbar: pagingBar,
        
        height:530,
        width:850,
        title:'Quelle - Kategorien - &Uuml;bersicht'
    });
	



    grid.render('grid-example');
	grid.getSelectionModel().selectFirstRow();
	

	Ext.onReady(function(){
			Ext.get('buttonbox').on('click', function(){
			var input = document.getElementById('textfeld').value;
			document.getElementById('textfeld').value='';
			var art_id = document.getElementById('art_id').value;
			if (trim(input) != '') {
				Ext.Ajax.request({  
				url : 'quelle.php?speicherNeueKategorie&value=' + input + '&art_id='+art_id, 				
				success: function(objServerResponse){  
					Ext.Ajax.request({  
						url : 'quelle.php?ladeQuelleKategorie&id='+art_id,  
						success: function(objServerResponse){  
							myData =  Ext.decode(objServerResponse.responseText);
							store.removeAll();
							store.loadData(myData);
					},  
						failure : function(objServerResponse){   
							alert ("Ajax Fehler!");
						}  
					});  
				},  
				failure : function(objServerResponse){   
					alert ("Ajax Fehler!");
				}  
			});  
			}
		});
	});
});

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}